package com.ygqh.customs.model;

import com.ygqh.common.AbstractObject;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ResultSet<T> extends AbstractObject {
    private static final long serialVersionUID = -6773582502393439819L;
    private long total = 0;
    private List<T> result = new ArrayList<T>();

    public ResultSet() {

    }

    public ResultSet(long total, List<T> result) {
        this.total = total;
        this.result = result;
    }

    public ResultSet(long total, List<T> result, String modifyTime) {
        this.total = total;
        this.result = result;
    }

    public ResultSet(List<T> result) {
        this.total = result == null ? 0 : result.size();
        this.result = result;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    public Map<String, Object> toJq() {
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("total", this.total);
        map.put("rows", this.result);

        return map;
    }

    public Map<String, Object> toDatatables(String sEcho) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", result);
        map.put("iTotalRecords", total);
        map.put("iTotalDisplayRecords", total);
        map.put("sEcho", sEcho);
        return map;
    }

    public Map<String, Object> toDatatables(String sEcho, String ext) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", result);
        map.put("iTotalRecords", total);
        map.put("iTotalDisplayRecords", total);
        map.put("ext", ext);
        map.put("sEcho", sEcho);
        return map;
    }

}